/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fxgreader;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author perkintang
 */
public class FileUtil {

    public static void saveToFile(InputStream in, File tofile) throws IOException {
        OutputStream out = null;
        try {
            out = new FileOutputStream(tofile);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
        } catch (Exception ex) {
            Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            out.close();
        }
    }

    public static String getPath(String filename) {
        File f = new File("./" + filename);
        return f.getAbsolutePath();
    }

    public static boolean fileExist(String filename) {
        File f = new File("./" + filename);
        return f.exists();
    }
}
